package com.xing.fruit.service.user;

import com.xing.fruit.dao.DatabaseDao;
import com.xing.fruit.dao.user.UserDao;
import com.xing.fruit.dao.user.UserDaoImpl;
import com.xing.fruit.pojo.User;

import java.util.List;

public class UserServiceImpl implements UserService{
    private UserDao userDao;
    DatabaseDao databaseDao = new DatabaseDao();
    public UserServiceImpl(){
        userDao = new UserDaoImpl();
    }
    //得到登录用户
    @Override
    public User getLoginUser(String username, String password) {
        User loginUser = null;
         loginUser = userDao.getLoginUser(username, password);
        return loginUser;
    }
    //注册用户
    @Override
    public int userReg(User user) {
        int i = 0 ;
         i = userDao.userReg(user);
         return i;
    }

    //得到全部用户
    @Override
    public List<User> getUserList() {
        List<User> userList = userDao.getUserList();
        return userList;
    }
    //通过id查询用户
    @Override
    public User getUserById(int id) {
        User userById = userDao.getUserById(id);
        return userById;
    }
    //修改用户
    @Override
    public int updateUser(User user) {
        int i = 0;
        i = userDao.updateUser(user);
        return i;
    }

    @Override
    public int updatePwd(String password, String username) {
        int i = userDao.updatePwd(password, username);
        return i;
    }

    //删除用户
    @Override
    public int deleteUser(int id) {
        int i = userDao.deleteUser(id);
        return i;
    }
}
